home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxd / tif_compress.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  147 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/fax/faxd/RCS/tif_compress.c,v 1.2 1994/02/28 18:25:30 sam Rel $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 Sam Leffler
  7.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library
  31.  *
  32.  * Compression Scheme Configuration Support.
  33.  */
  34. #include "tiffiop.h"
  35.  
  36. typedef struct {
  37.     char*    name;
  38.     int    scheme;
  39.     TIFFVoidMethod    init;
  40. } cscheme_t;
  41. static const cscheme_t CompressionSchemes[] = {
  42.     { "Null",        COMPRESSION_NONE,    TIFFInitDumpMode },
  43.     { "LZW",        COMPRESSION_LZW,    TIFFInitDumpMode },
  44.     { "PackBits",    COMPRESSION_PACKBITS,    TIFFInitDumpMode },
  45.     { "ThunderScan",    COMPRESSION_THUNDERSCAN,TIFFInitDumpMode },
  46.     { "NeXT",        COMPRESSION_NEXT,    TIFFInitDumpMode },
  47.     { "JPEG",        COMPRESSION_JPEG,    TIFFInitDumpMode },
  48.     { "CCITT RLE",    COMPRESSION_CCITTRLE,    TIFFInitDumpMode },
  49.     { "CCITT RLE/W",    COMPRESSION_CCITTRLEW,    TIFFInitDumpMode },
  50.     { "CCITT Group3",    COMPRESSION_CCITTFAX3,    TIFFInitDumpMode },
  51.     { "CCITT Group4",    COMPRESSION_CCITTFAX4,    TIFFInitDumpMode },
  52. };
  53. #define    NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
  54.  
  55. static const cscheme_t *
  56. DECLARE1(findScheme, int, scheme)
  57. {
  58.     register const cscheme_t *c;
  59.  
  60.     for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
  61.         if (c->scheme == scheme)
  62.             return (c);
  63.     return ((const cscheme_t *)0);
  64. }
  65.  
  66. static int
  67. DECLARE2(TIFFNoEncode, TIFF*, tif, char*, method)
  68. {
  69.     const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
  70.     TIFFError(tif->tif_name,
  71.         "%s %s encoding is not implemented", c->name, method);
  72.     return (-1);
  73. }
  74.  
  75. int
  76. DECLARE4(TIFFNoRowEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  77. {
  78.     return (TIFFNoEncode(tif, "scanline"));
  79. }
  80.  
  81. int
  82. DECLARE4(TIFFNoStripEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  83. {
  84.     return (TIFFNoEncode(tif, "strip"));
  85. }
  86.  
  87. int
  88. DECLARE4(TIFFNoTileEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  89. {
  90.     return (TIFFNoEncode(tif, "tile"));
  91. }
  92.  
  93. static int
  94. DECLARE2(TIFFNoDecode, TIFF*, tif, char*, method)
  95. {
  96.     const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
  97.     TIFFError(tif->tif_name,
  98.         "%s %s decoding is not implemented", c->name, method);
  99.     return (-1);
  100. }
  101.  
  102. int
  103. DECLARE4(TIFFNoRowDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  104. {
  105.     return (TIFFNoDecode(tif, "scanline"));
  106. }
  107.  
  108. int
  109. DECLARE4(TIFFNoStripDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  110. {
  111.     return (TIFFNoDecode(tif, "strip"));
  112. }
  113.  
  114. int
  115. DECLARE4(TIFFNoTileDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  116. {
  117.     return (TIFFNoDecode(tif, "tile"));
  118. }
  119.  
  120. int
  121. DECLARE2(TIFFSetCompressionScheme, TIFF*, tif, int, scheme)
  122. {
  123.     const cscheme_t *c = findScheme(scheme);
  124.  
  125.     if (!c) {
  126.         TIFFError(tif->tif_name,
  127.             "Unknown data compression algorithm %u (0x%x)",
  128.             scheme, scheme);
  129.         return (0);
  130.     }
  131.     tif->tif_predecode = NULL;
  132.     tif->tif_decoderow = TIFFNoRowDecode;
  133.     tif->tif_decodestrip = TIFFNoStripDecode;
  134.     tif->tif_decodetile = TIFFNoTileDecode;
  135.     tif->tif_preencode = NULL;
  136.     tif->tif_postencode = NULL;
  137.     tif->tif_encoderow = TIFFNoRowEncode;
  138.     tif->tif_encodestrip = TIFFNoStripEncode;
  139.     tif->tif_encodetile = TIFFNoTileEncode;
  140.     tif->tif_close = NULL;
  141.     tif->tif_seek = NULL;
  142.     tif->tif_cleanup = NULL;
  143.     tif->tif_flags &= ~TIFF_NOBITREV;
  144.     tif->tif_options = 0;
  145.     return ((*c->init)(tif));
  146. }
  147.